<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>cup.res.mac &#8212; cup 3.2.33 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/alabaster.css" />
    <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/sphinx_highlight.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
   
  <link rel="stylesheet" href="../../../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <h1>Source code for cup.res.mac</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf-8 -*</span>
<span class="c1"># Authors: shouc (https://github.com/shouc)</span>
<span class="c1"># Modifier: Guannan Ma (@mythmgn)</span>
<span class="c1"># copyright:</span>
<span class="c1">#    Copyright [CUP] - See LICENSE for details.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">query mac resource module</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">collections</span>

<span class="kn">import</span> <span class="nn">psutil</span>

<span class="kn">from</span> <span class="nn">cup</span> <span class="kn">import</span> <span class="n">unittest</span>
<span class="kn">from</span> <span class="nn">cup</span> <span class="kn">import</span> <span class="n">decorators</span>


<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span>
    <span class="s1">&#39;get_kernel_version&#39;</span><span class="p">,</span> <span class="s1">&#39;get_cpu_nums&#39;</span><span class="p">,</span>
    <span class="s1">&#39;get_disk_usage_all&#39;</span><span class="p">,</span> <span class="s1">&#39;get_disk_info&#39;</span>
<span class="p">]</span>

<span class="n">_CPU_COLUMNS</span> <span class="o">=</span> <span class="p">[</span>
    <span class="s1">&#39;usr&#39;</span><span class="p">,</span>
    <span class="s1">&#39;nice&#39;</span><span class="p">,</span>
    <span class="s1">&#39;system&#39;</span><span class="p">,</span>
    <span class="s1">&#39;idle&#39;</span>
<span class="p">]</span>
<span class="n">_MEM_COLUMNS</span> <span class="o">=</span> <span class="p">[</span>
    <span class="s1">&#39;total&#39;</span><span class="p">,</span>
    <span class="s1">&#39;avail&#39;</span><span class="p">,</span>
    <span class="s1">&#39;percent&#39;</span><span class="p">,</span>
    <span class="s1">&#39;used&#39;</span><span class="p">,</span>
    <span class="s1">&#39;free&#39;</span><span class="p">,</span>
    <span class="s1">&#39;active&#39;</span><span class="p">,</span>
    <span class="s1">&#39;inactive&#39;</span><span class="p">,</span>
    <span class="s1">&#39;wired&#39;</span>
<span class="p">]</span>


<span class="k">class</span> <span class="nc">CPUInfo</span><span class="p">(</span><span class="n">collections</span><span class="o">.</span><span class="n">namedtuple</span><span class="p">(</span><span class="s1">&#39;CPUInfo&#39;</span><span class="p">,</span> <span class="n">_CPU_COLUMNS</span><span class="p">)):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    CPUInfo is used for get_cpu_usage function. The following attr will be</span>
<span class="sd">    in the namedtuple:</span>
<span class="sd">    usr,</span>
<span class="sd">    nice,</span>
<span class="sd">    system,</span>
<span class="sd">    idle</span>

<span class="sd">    I.g.</span>
<span class="sd">    ::</span>

<span class="sd">        import cup</span>
<span class="sd">        # count cpu usage</span>
<span class="sd">        from cup.res import linux</span>
<span class="sd">        cpuinfo = mac.get_cpu_usage(intvl_in_sec=60)</span>
<span class="sd">        print cpuinfo.usr</span>
<span class="sd">    &quot;&quot;&quot;</span>


<span class="k">class</span> <span class="nc">MemInfo</span><span class="p">(</span><span class="n">collections</span><span class="o">.</span><span class="n">namedtuple</span><span class="p">(</span><span class="s1">&#39;vmem&#39;</span><span class="p">,</span> <span class="n">_MEM_COLUMNS</span><span class="p">)):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    MemInfo</span>
<span class="sd">    wired (BSD, macOS): memory that is marked to always stay in RAM.</span>
<span class="sd">                It is never moved to disk.</span>
<span class="sd">    &quot;&quot;&quot;</span>


<div class="viewcode-block" id="get_kernel_version"><a class="viewcode-back" href="../../../cup.res.html#cup.res.mac.get_kernel_version">[docs]</a><span class="k">def</span> <span class="nf">get_kernel_version</span><span class="p">():</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    get kernel info of mac.</span>
<span class="sd">    e.g.(&#39;16&#39;, &#39;7&#39;, &#39;0&#39;):</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nd">@decorators</span><span class="o">.</span><span class="n">needmac</span>
    <span class="k">def</span> <span class="nf">_get_kernel_version</span><span class="p">():</span>
        <span class="n">versions</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">uname</span><span class="p">()[</span><span class="mi">2</span><span class="p">]</span>
        <span class="k">return</span> <span class="nb">tuple</span><span class="p">([</span><span class="n">info</span> <span class="k">for</span> <span class="n">info</span> <span class="ow">in</span> <span class="n">versions</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)])</span>
    <span class="k">return</span> <span class="n">_get_kernel_version</span><span class="p">()</span></div>


<div class="viewcode-block" id="get_cpu_nums"><a class="viewcode-back" href="../../../cup.res.html#cup.res.mac.get_cpu_nums">[docs]</a><span class="k">def</span> <span class="nf">get_cpu_nums</span><span class="p">():</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    return cpu num</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nd">@decorators</span><span class="o">.</span><span class="n">needmac</span>
    <span class="k">def</span> <span class="nf">_get_cpu_nums</span><span class="p">():</span>
        <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">sysconf</span><span class="p">(</span><span class="s2">&quot;SC_NPROCESSORS_ONLN&quot;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">_get_cpu_nums</span><span class="p">()</span></div>


<div class="viewcode-block" id="get_disk_usage_all"><a class="viewcode-back" href="../../../cup.res.html#cup.res.mac.get_disk_usage_all">[docs]</a><span class="k">def</span> <span class="nf">get_disk_usage_all</span><span class="p">(</span><span class="n">raw</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    :param raw:</span>
<span class="sd">        measure set to Byte if Raw is True</span>
<span class="sd">    :return:</span>
<span class="sd">        a py dict: { &#39;totalSpace&#39;: xxx, &#39;usedSpace&#39;: xxx, &#39;freeSpace&#39;: xxx,</span>
<span class="sd">        &#39;unit&#39;: xxx</span>
<span class="sd">        }</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nd">@decorators</span><span class="o">.</span><span class="n">needmac</span>
    <span class="k">def</span> <span class="nf">_get_disk_usage_all</span><span class="p">(</span><span class="n">raw</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="n">byte2gb</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span>
        <span class="n">byte2mb</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span>
        <span class="n">stat</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">statvfs</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">)</span>
        <span class="n">free</span> <span class="o">=</span> <span class="n">stat</span><span class="o">.</span><span class="n">f_bavail</span> <span class="o">*</span> <span class="n">stat</span><span class="o">.</span><span class="n">f_frsize</span>
        <span class="n">total</span> <span class="o">=</span> <span class="n">stat</span><span class="o">.</span><span class="n">f_blocks</span> <span class="o">*</span> <span class="n">stat</span><span class="o">.</span><span class="n">f_frsize</span>
        <span class="n">unit</span> <span class="o">=</span> <span class="s2">&quot;Byte&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">raw</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">total</span> <span class="o">&gt;</span> <span class="n">byte2gb</span><span class="p">:</span>
                <span class="n">free</span><span class="p">,</span> <span class="n">total</span> <span class="o">=</span> \
                    <span class="n">free</span> <span class="o">/</span> <span class="n">byte2gb</span><span class="p">,</span> <span class="n">total</span> <span class="o">/</span> <span class="n">byte2gb</span>
                <span class="n">unit</span> <span class="o">=</span> <span class="s2">&quot;GB&quot;</span>
            <span class="k">elif</span> <span class="n">total</span> <span class="o">&gt;</span> <span class="n">byte2mb</span><span class="p">:</span>
                <span class="n">free</span><span class="p">,</span> <span class="n">total</span> <span class="o">=</span> \
                    <span class="n">free</span> <span class="o">/</span> <span class="n">byte2mb</span><span class="p">,</span> <span class="n">total</span> <span class="o">/</span> <span class="n">byte2mb</span>
                <span class="n">unit</span> <span class="o">=</span> <span class="s2">&quot;MB&quot;</span>
        <span class="k">return</span> <span class="p">{</span>
            <span class="s2">&quot;totalSpace&quot;</span><span class="p">:</span> <span class="n">total</span><span class="p">,</span>
            <span class="s2">&quot;usedSpace&quot;</span><span class="p">:</span> <span class="n">total</span> <span class="o">-</span> <span class="n">free</span><span class="p">,</span>
            <span class="s2">&quot;freeSpace&quot;</span><span class="p">:</span> <span class="n">free</span><span class="p">,</span>
            <span class="s2">&quot;unit&quot;</span><span class="p">:</span><span class="n">unit</span>
        <span class="p">}</span>
    <span class="k">return</span> <span class="n">_get_disk_usage_all</span><span class="p">(</span><span class="n">raw</span><span class="p">)</span></div>


<div class="viewcode-block" id="get_disk_info"><a class="viewcode-back" href="../../../cup.res.html#cup.res.mac.get_disk_info">[docs]</a><span class="k">def</span> <span class="nf">get_disk_info</span><span class="p">():</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    :return:</span>
<span class="sd">        get disk info from the current macOS</span>

<span class="sd">    :raise Exception:</span>
<span class="sd">        RuntimeError, if got no disk at all</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nd">@decorators</span><span class="o">.</span><span class="n">needmac</span>
    <span class="k">def</span> <span class="nf">_get_disk_info</span><span class="p">():</span>
        <span class="n">info</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">popen</span><span class="p">(</span><span class="s2">&quot;df -lh&quot;</span><span class="p">)</span>
        <span class="n">all_diskinfo</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">info</span><span class="o">.</span><span class="n">readlines</span><span class="p">()):</span>
            <span class="k">if</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">blockinfo</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">block</span> <span class="ow">in</span> <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">):</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">block</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">blockinfo</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">block</span><span class="p">)</span>
                <span class="n">all_diskinfo</span><span class="o">.</span><span class="n">append</span><span class="p">({</span>
                    <span class="s2">&quot;FileSystem&quot;</span><span class="p">:</span>  <span class="n">blockinfo</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                    <span class="s2">&quot;Size&quot;</span><span class="p">:</span>        <span class="n">blockinfo</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                    <span class="s2">&quot;Used&quot;</span><span class="p">:</span>        <span class="n">blockinfo</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
                    <span class="s2">&quot;Available&quot;</span><span class="p">:</span>   <span class="n">blockinfo</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span>
                    <span class="s2">&quot;Percentage&quot;</span><span class="p">:</span>  <span class="n">blockinfo</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span>
                    <span class="p">})</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">continue</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">all_diskinfo</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;couldn&#39;t find disk&quot;</span><span class="p">)</span></div>



<span class="k">def</span> <span class="nf">get_cpu_usage</span><span class="p">(</span><span class="n">intvl_in_sec</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    get cpu usage statistics during a time period (intvl_in_sec), return a</span>
<span class="sd">    namedtuple CPUInfo</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">unittest</span><span class="o">.</span><span class="n">assert_gt</span><span class="p">(</span><span class="n">intvl_in_sec</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">_CPU_COLUMNS</span><span class="p">)):</span>
        <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">cpu_info0</span> <span class="o">=</span> <span class="n">psutil</span><span class="o">.</span><span class="n">cpu_times</span><span class="p">()</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">intvl_in_sec</span><span class="p">)</span>
    <span class="n">cpu_info1</span> <span class="o">=</span> <span class="n">psutil</span><span class="o">.</span><span class="n">cpu_times</span><span class="p">()</span>
    <span class="n">total</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cpu_info1</span><span class="p">)):</span>
        <span class="n">minus</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cpu_info1</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">-</span> <span class="nb">float</span><span class="p">(</span><span class="n">cpu_info0</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
        <span class="n">total</span> <span class="o">=</span> <span class="n">total</span> <span class="o">+</span> <span class="n">minus</span>
        <span class="n">ret</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">minus</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">ret</span><span class="p">)):</span>
        <span class="n">ret</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">ret</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="mi">100</span> <span class="o">/</span> <span class="n">total</span>
    <span class="k">return</span> <span class="n">CPUInfo</span><span class="p">(</span><span class="o">*</span><span class="n">ret</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">get_meminfo</span><span class="p">():</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;get mem info of mac&quot;&quot;&quot;</span>
    <span class="n">meminfo</span> <span class="o">=</span> <span class="n">psutil</span><span class="o">.</span><span class="n">virtual_memory</span><span class="p">()</span>
    <span class="k">return</span> <span class="n">MemInfo</span><span class="p">(</span>
        <span class="n">meminfo</span><span class="o">.</span><span class="n">total</span><span class="p">,</span>
        <span class="n">meminfo</span><span class="o">.</span><span class="n">available</span><span class="p">,</span>
        <span class="n">meminfo</span><span class="o">.</span><span class="n">percent</span><span class="p">,</span>
        <span class="n">meminfo</span><span class="o">.</span><span class="n">used</span><span class="p">,</span>
        <span class="n">meminfo</span><span class="o">.</span><span class="n">free</span><span class="p">,</span>
        <span class="n">meminfo</span><span class="o">.</span><span class="n">active</span><span class="p">,</span>
        <span class="n">meminfo</span><span class="o">.</span><span class="n">inactive</span><span class="p">,</span>
        <span class="n">meminfo</span><span class="o">.</span><span class="n">wired</span>
    <span class="p">)</span>


<span class="k">def</span> <span class="nf">get_net_through</span><span class="p">(</span><span class="n">str_interface</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    get net through</span>

<span class="sd">    Raise ValueError if interface does not exists</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">net_trans</span> <span class="o">=</span> <span class="n">psutil</span><span class="o">.</span><span class="n">net_io_counters</span><span class="p">(</span><span class="kc">True</span><span class="p">)[</span><span class="n">str_interface</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;interface </span><span class="si">{0}</span><span class="s1"> not exist&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">str_interface</span><span class="p">))</span>
    <span class="k">return</span> <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">net_trans</span><span class="o">.</span><span class="n">bytes_recv</span><span class="p">),</span> <span class="nb">int</span><span class="p">(</span><span class="n">net_trans</span><span class="o">.</span><span class="n">bytes_sent</span><span class="p">))</span>


<span class="k">def</span> <span class="nf">get_net_transmit_speed</span><span class="p">(</span><span class="n">str_interface</span><span class="p">,</span> <span class="n">intvl_in_sec</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;get network interface write/read speed&quot;&quot;&quot;</span>
    <span class="n">decorators</span><span class="o">.</span><span class="n">needmac</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">unittest</span><span class="o">.</span><span class="n">assert_gt</span><span class="p">(</span><span class="n">intvl_in_sec</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">rx_bytes0</span> <span class="o">=</span> <span class="n">get_net_through</span><span class="p">(</span><span class="n">str_interface</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">intvl_in_sec</span><span class="p">)</span>
    <span class="n">rx_bytes1</span> <span class="o">=</span> <span class="n">get_net_through</span><span class="p">(</span><span class="n">str_interface</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">rx_bytes1</span> <span class="o">-</span> <span class="n">rx_bytes0</span><span class="p">)</span> <span class="o">/</span> <span class="n">intvl_in_sec</span>


<span class="k">def</span> <span class="nf">get_net_recv_speed</span><span class="p">(</span><span class="n">str_interface</span><span class="p">,</span> <span class="n">intvl_in_sec</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    get average network recv-speed during a time period (intvl_in_sec)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">decorators</span><span class="o">.</span><span class="n">needmac</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">unittest</span><span class="o">.</span><span class="n">assert_gt</span><span class="p">(</span><span class="n">intvl_in_sec</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">tx_bytes0</span> <span class="o">=</span> <span class="n">get_net_through</span><span class="p">(</span><span class="n">str_interface</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">intvl_in_sec</span><span class="p">)</span>
    <span class="n">tx_bytes1</span> <span class="o">=</span> <span class="n">get_net_through</span><span class="p">(</span><span class="n">str_interface</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">tx_bytes1</span> <span class="o">-</span> <span class="n">tx_bytes0</span><span class="p">)</span> <span class="o">/</span> <span class="n">intvl_in_sec</span>


<span class="k">if</span> <span class="s1">&#39;__main__&#39;</span> <span class="o">==</span> <span class="vm">__name__</span><span class="p">:</span>
    <span class="c1"># system info</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">get_cpu_nums</span><span class="p">())</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">get_kernel_version</span><span class="p">())</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">get_disk_usage_all</span><span class="p">())</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">get_disk_info</span><span class="p">())</span>
</pre></div>

          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../../../index.html">cup</a></h1>








<h3>Navigation</h3>
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../cup.html">cup package</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../../../index.html">Documentation overview</a><ul>
  <li><a href="../../index.html">Module code</a><ul>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2023, CUP-DEV Team.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 7.0.1</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
      
    </div>

    

    
  </body>
</html>